#include <stdio.h>
#include <stdlib.h>

/*
 * A tool to create a "kong dong" file, which will fill the file space with "00"
 * Usage : ./a.out <file_path> <file_size>
 * 
 * int fseek(FILE *stream, long offset, int whence);
 * long ftell(FILE *stream);
 * void rewind(FILE *stream);
 *
 * The  rewind()  function equivalent to:
 * (void) fseek(stream, 0L, SEEK_SET)
 */
int main(int argc, char *argv[])
{
	if (argc != 3) {
		fprintf(stderr, "Usage : %s <file_path> <file_size>\n", argv[0]);
		exit(1);
	}

	FILE *fp1 = NULL;
	long file_size = atol(argv[2]);

	if ((fp1 = fopen(argv[1], "w")) == NULL) {
		perror("fopen()");
		exit(1);
	}
	
	// fseek(fp1, file_size, SEEK_SET) fill the empty file with "00" to file_size
	fseek(fp1, file_size, SEEK_SET);
	printf("%ld\n", file_size);
	fclose(fp1);

	exit(0);
}
